package com.unicom.office.templatefunc;

import com.unicom.office.type.NumberTypeItem;
import com.unicom.office.var.NumberVarItem;
import com.unicom.office.type.TypeItem;
import com.unicom.office.dataitem.NumberDataItem;
import com.unicom.office.runtime.OfficeRuntime;
import com.unicom.office.node.OfficeNode;
import com.unicom.office.node.OfficeNodeType;
import com.unicom.office.unit.OfficeUnit;

import java.util.List;
import java.util.Set;

public class RoundFunc extends TemplateFunc {
    public static final RoundFunc INSTANCE = new RoundFunc();

    private RoundFunc(){}

    public Set<OfficeNodeType> getNodeTypes() {
        return null;
    }

    public String getName() {
        return "round";
    }

    public TypeItem getType() {
        return NumberTypeItem.INSTANCE;
    }

    public Object run(List<Object> params, OfficeRuntime officeRuntime) {
        NumberDataItem num = (NumberDataItem) params.get(0);
        long round = Math.round(num.getDoubleValue());
        return NumberDataItem.create(round);
    }

    public void runForMatch(OfficeUnit unit, List<Object> params, OfficeRuntime officeRuntime) {

    }
}
